package com.kly.user.rulePolicy.enums;

/**
 * @author linqu
 */
public enum PolicyComposeEnum {

    /**
     * 规则的组合方式: 首次匹配（顺序执行）| 最坏匹配（并行执行）
     * WLM下发规则采用首次匹配，防打扰采用并行匹配规则
     *
     */

    FIRST, WORST;


    public static PolicyComposeEnum transformByType(Integer type) {
        for (PolicyComposeEnum policyComposeEnum : PolicyComposeEnum.values()) {
            if (policyComposeEnum.ordinal() + 1 == type) {
                return policyComposeEnum;
            }
        }
        return null;
    }

    public static PolicyComposeEnum transformByName(String name) {
        if (PolicyComposeEnum.WORST.name().equalsIgnoreCase(name)) {
            return PolicyComposeEnum.WORST;
        } else if (PolicyComposeEnum.FIRST.name().equalsIgnoreCase(name)) {
            return PolicyComposeEnum.FIRST;
        } else {
            return null;
        }
    }

    public static void main(String[] args) {
        PolicyComposeEnum policyComposeEnum = transformByType(2);
        System.out.println(policyComposeEnum);


        final PolicyComposeEnum first = PolicyComposeEnum.transformByName("first");
        System.out.println(first.name());

    }

}
